package com.osmino.contacts.groups;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.osmino.contacts.entity.Group;

public final class GroupsAdapter extends BaseAdapter {
	
	public static final int DND_POSITION_UNDEF = -1;
	private final Context mContext;
	private List<Group> mListInfo;
	private int mDNDPos = DND_POSITION_UNDEF;
	
	public GroupsAdapter(Context context) {
		mContext = context;
		mListInfo = new ArrayList<Group>();
	}

	@Override
	public int getCount() {
		return mListInfo.size();
	}

	@Override
	public Group getItem(int position) {
		return mListInfo.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		GroupItem item = null;
		if (convertView == null) {
			item = new GroupItem(mContext);
		} else {
			item = (GroupItem) convertView;
		}
		item.setInfo(mListInfo.get(position));
		Log.e("ADPTR", position + ":" + Boolean.toString(position == mDNDPos));
		item.setBelowDND(position == mDNDPos);
		return item;
	}

	public void setListGroups(List<Group> listGroupInfo) {
		mListInfo = listGroupInfo;
		notifyDataSetChanged();
	}
	
	public void setGroupBelowDND(int position){
		if(position < 0)
			return;
		if(position != mDNDPos){
			Log.w("GAD", "IF");
			mDNDPos = position;
//			notifyDataSetChanged();
		}
		else{
			Log.w("GAD", "ELSE");
		}
	}
}
